package cn.mw.cmdb.entity;

import lombok.Data;

import java.io.Serializable;
import java.util.Map;

@Data
public class PropertyTypeRef implements Serializable {
    public static final String ID = "id";

    private String typeId;

    private Object defaultValue;

    private Map<String, Object> context;

    public PropertyTypeRef() {
    }

    public PropertyTypeRef(String typeId){
        this.typeId = typeId;
    }

    public PropertyType getPropertyType(){
        return PropertyTypeManage.getPropertyType(typeId);
    }

    public String getValue(String key){
        if(null != context){
            return context.get(key).toString();
        }

        return null;
    }

    public <T> T getValue(String key, Class<T> tClass){
        if(null != context){
            return (T)context.get(key);
        }

        return null;
    }
}
